﻿#ifndef CUSTOMDELEGATE_H
#define CUSTOMDELEGATE_H

#include "EditorFactory.h"
#include <QStyledItemDelegate>
#include <QMap>

class CustomDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    explicit CustomDelegate(QObject *parent = nullptr);

    void registerFactory(int column, EditorFactory* factory);

    QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
                          const QModelIndex& index) const override;
    void setEditorData(QWidget* editor, const QModelIndex& index) const override;
    void setModelData(QWidget* editor, QAbstractItemModel* model,
                      const QModelIndex& index) const override;

private:
    // 列号 -> 工厂
    QMap<int, EditorFactory*> m_factories;
};

#endif // CUSTOMDELEGATE_H
